#ifndef BONJOURSERVICEBROWSER_H
#define BONJOURSERVICEBROWSER_H

#include <QtGui/QTreeWidget>
#include <QSocketNotifier>

#ifdef _WIN32
	typedef unsigned short UINT16;
	typedef unsigned int UINT18;
	typedef unsigned char UINT8;
	typedef signed char INT8;
	typedef short INT16;
#endif

#include <dns_sd.h>

#include "../Common/bonjourrecord.h"


/** Class allows for Bonjour WeaveEdit services to be browsed by a client. */
class BonjourServiceBrowser : public QTreeWidget
{
	Q_OBJECT

	public:

		BonjourServiceBrowser(QWidget *parent);

		~BonjourServiceBrowser();

		void browseForServiceType(const QString serviceType);

		/** List of available services. */
		inline QList<BonjourRecord> currentRecords() const { return bonjourRecords; }
		inline QString serviceType() const { return browsingType; }

	signals:
		void currentBonjourRecordsChanged(const QList<BonjourRecord> &list);
		void error(DNSServiceErrorType err);

	private slots:
		void bonjourSocketReadyRead();

	private:
		static void DNSSD_API bonjourBrowseReply(DNSServiceRef,
							 DNSServiceFlags flags,
							 quint32,
							 DNSServiceErrorType errorCode,
							 const char *serviceName,
							 const char *regType,
							 const char *replyDomain,
							 void *context);

		DNSServiceRef dnssref;
		QSocketNotifier *bonjourSocket;
		QList<BonjourRecord> bonjourRecords;
		QString browsingType;
};

#endif // BONJOURSERVICEBROWSER_H
